#!/usr/bin/env bash

#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

set -e

S2N_QUIC_FILES=$(find "$PWD" -type f \( -name "*.rs" -o -name "*.py" \) -not -path "*/target/*")

FAILED=0

for file in $S2N_QUIC_FILES; do
    # The phrase "Copyright Amazon.com, Inc. or its affiliates." should appear at least once in the first 3 lines of every file
    COUNT=`head -3 $file | grep -i "Copyright Amazon.com, Inc. or its affiliates." | wc -l`;
    if [ $COUNT == 0 ]; then
        FAILED=1;
        echo "Copyright Check Failed: $file";
    fi
done

if [ $FAILED == 1 ]; then
    printf "\\033[31;1mFAILED Copyright Check\\033[0m\\n"
    exit -1
else
    printf "\\033[32;1mPASSED Copyright Check\\033[0m\\n"
fi
